/*
 * @(#)GaeaRegistry.java	1.0 Apr 27, 2008
 *
 *	The MIT License
 *
 *	Copyright (c) 2008 Malachi de AElfweald <malachid@gmail.com>
 *
 *	Permission is hereby granted, free of charge, to any person obtaining a copy
 *	of this software and associated documentation files (the "Software"), to deal
 *	in the Software without restriction, including without limitation the rights
 *	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *	copies of the Software, and to permit persons to whom the Software is
 *	furnished to do so, subject to the following conditions:
 *
 *	The above copyright notice and this permission notice shall be included in
 *	all copies or substantial portions of the Software.
 *
 *	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *	THE SOFTWARE.
 */
package org.eoti.gaea.db;

import org.eoti.mimir.MimirException;
import org.eoti.mimir.MimirRegistry;
import org.eoti.spec.mimirdb.v1.DBMapping;

import java.io.File;

public class GaeaRegistry extends MimirRegistry
{
	protected EventDB eventDB;
	protected LocationDB locationDB;
	protected NamePrefixDB namePrefixDB;
	protected NameSuffixDB nameSuffixDB;
	protected NameTitleDB nameTitleDB;
	protected PersonDB personDB;
	protected RelationDB relationDB;

	public GaeaRegistry()
			throws MimirException
	{
		super();
	}

	public GaeaRegistry(File databaseRoot)
			throws MimirException
	{
		super(databaseRoot);
	}

	public EventDB getEventDB(){return eventDB;}
	public LocationDB getLocationDB(){return locationDB;}
	public NamePrefixDB getNamePrefixDB(){return namePrefixDB;}
	public NameSuffixDB getNameSuffixDB(){return nameSuffixDB;}
	public NameTitleDB getNameTitleDB(){return nameTitleDB;}
	public PersonDB getPersonDB(){return personDB;}
	public RelationDB getRelationDB(){return relationDB;}

	protected void addDefaultMappings()
			throws MimirException
	{
		super.addDefaultMappings();

		DBMapping commonMapping = new DBMapping();
		commonMapping.setId("gaea-common-1.0");
		commonMapping.setNamespacePrefix("gaea");
		commonMapping.setNamespaceURI("http://eoti.org/spec/gaea/common/1.0");
		commonMapping.setSpecPackage("org.eoti.spec.gaea.common.v1");
		commonMapping.setSchema(getSchemaLocation("/org/eoti/spec/gaea/gaea-common-1.0.xsd"));
		commonMapping.setDirectory(".");//???
		addMapping(commonMapping);

		eventDB = new EventDB(this, addGaeaMapping("event"));
		locationDB = new LocationDB(this, addGaeaMapping("location"));
		namePrefixDB = new NamePrefixDB(this, addGaeaMapping("prefix"));
		nameSuffixDB = new NameSuffixDB(this, addGaeaMapping("suffix"));
		nameTitleDB = new NameTitleDB(this, addGaeaMapping("title"));
		personDB = new PersonDB(this, addGaeaMapping("person"));
		relationDB = new RelationDB(this, addGaeaMapping("relation"));
	}

	protected DBMapping addGaeaMapping(String name)
			throws MimirException
	{
		DBMapping mapping = new DBMapping();
		mapping.setId(String.format("gaea-%s-1.0", name));
		mapping.setNamespacePrefix(name);
		mapping.setNamespaceURI(String.format("http://eoti.org/spec/gaea/%s/1.0", name));
		mapping.setSpecPackage(String.format("org.eoti.spec.gaea.%s.v1", name));
		mapping.setSchema(getSchemaLocation(String.format("/org/eoti/spec/gaea/gaea-%s-1.0.xsd", name)));
		mapping.setDirectory(".");//???
		addMapping(mapping);
		return mapping;
	}
}
